#ifndef __BE_SCRIPTABLE__
#define __BE_SCRIPTABLE__

class TmpClass;
class TestClass;

class Scriptable
{
 protected:
  StringHash nameHash;

 private:
  Scriptable( const char * const _str); 
  Scriptable( const StringHash &_hash );

 public:
  virtual ~Scriptable();
  virtual bool setValue(StringHash _name, float _value) = 0;
};

template<class _X>
class ScriptObject : public Scriptable
{
 public:
  typedef void (_X::*MemFunc)( const float & );
  typedef std::map< StringHash, MemFunc > HashFuncMap;
  typedef typename HashFuncMap::iterator HashFuncMapIterator;

  public:
  static HashFuncMap setterMap;
  
 protected:
  static void registerSetter(const char * const _name, MemFunc _func)
  {
    StringHash h = System::hash(_name);
    setterMap.insert(std::make_pair(h, _func));
  }
  
 public:
 ScriptObject(const StringHash &_hash):Scriptable(_hash) {};
 ScriptObject(const char * const _str):Scriptable(_str) {};
  ~ScriptObject()
    {};
  
  bool setValue(StringHash _name, float _value)
  {
    HashFuncMapIterator it;

    it = ScriptObject::setterMap.find(_name);

    if ( it == ScriptObject::setterMap.end() )
      return false;

    static_cast<_X*>(this)->*(it->second)(_value);
    return true;
  }
};


template<class _X>
typename ScriptObject<_X>::HashFuncMap ScriptObject<_X>::setterMap;


/*
class ScriptableObject
{
 protected:
  StringHash nameHash;

 protected:
  ScriptableObject();
  virtual ~ScriptableObject();
};

template< class _X >
class Scriptable : public ScriptableObject
{
 public:
  class BaseParam
  {
  private:
    StringHash hash;

  public:
    BaseParam(const char* const _str);
    BaseParam(const StringHash &_hash);
    virtual void set(const float &_value) = 0;  
    
    friend class Scriptable;
  };
  
  template<class _X, class _C>
    class Param : public BaseParam
  {
  private:
    const _X &data;

  public:
  Param(const char* const _str) : BaseParam(_str)
    {}
    
  Param(const StringHash &_hash, _X &_data) 
    : BaseParam( _hash), data(_data)
      {}

    void set(const float &_value)
    {
      data = _value;
    }
  };
  
 private:
  typedef std::map< StringHash, BaseParam* > HashParamMap;
  typedef HashParamMap::iterator HashParamMapIterator;

  static HashParamMap hashParamMap;
  static bool registerParam(BaseParam *_param);

 public:
  Scriptable();
  virtual ~Scriptable();

  template<class _X>
    bool registerParam( Param<_X> &_param)
    {
      return registerParam( &_param );
    }

  bool setValue(const StringHash &_name, const float  &_value);

  void setNameHash(const StringHash &_name);
  const StringHash & getNameHash() const;
};
*/
#endif
